import { createRouter, createWebHistory } from 'vue-router'
import HomeView from '../views/HomeView.vue'
import LoginView from '../views/LoginView.vue'
import ColumnManagement from '../views/Sheepfarm.vue/ColumnManagement.vue';

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: '/',
      name: 'login',
      component: LoginView,
    },
    {
      path: '/home',
      name: 'home',
      component: HomeView,
      children: [
        {
          path: '',
          name: 'dashboard',
          component: () => import('../views/AboutView.vue'),
        },
        {
          path: '/Permissiondisplay',
          name: 'Permissiondisplay',
          component: () => import('../views/RBAC/Permissiondisplay.vue'),
        },

        {
          path: '/RolesList',
          name: 'RolesList',
          component: () => import('../views/RBAC/RolesList.vue'),
        },

        {
          path: '/UserinfoList',
          name: 'UserinfoList',
          component: () => import('../views/RBAC/UserinfoList.vue'),
        },


        {
          //种母配种
          path: '/EweMatingList',
          name: 'EweMatingList',
          component: () => import('../views/production_a/EweMatingList.vue'),
        },
         {
          path: '/EweMating',
          name: 'EweMating',
          component: () => import('../views/production_a/EweMating.vue'),
        },

        {
          //种母妊检
          path: '/EwePregnancyExamination',
          name: 'EwePregnancyExamination',
          component: () => import('../views/production_a/EwePregnancyExamination.vue'),
        },
        {
          //种母妊检新增
          path: '/EwePregnancyExaminationAdd',
          name: 'EwePregnancyExaminationAdd',
          component: () => import('../views/production_a/EwePregnancyExaminationAdd.vue'),
        },
        {
          //种母妊检编辑
          path: '/EwePregnancyExaminationEdit',
          name: 'EwePregnancyExaminationEdit',
          component: () => import('../views/production_a/EwePregnancyExaminationEdit.vue'),
        },
        {
          //种母分娩
          path: '/EweLambing',
          name: 'EweLambing',
          component: () => import('../views/production_a/EweLambing.vue'),
        },
        {
          //种母分娩添加
          path: '/EweLambing/add',
          name: 'EweLambing/add',
          component: () => import('../views/production_a/EweLambingAdd.vue'),
        },
        {
          //种母断奶
          path: '/EweWeaning',
          name: 'EweWeaning',
          component: () => import('../views/production_a/EweWeaning.vue'),
        },
        {
          // 种母断奶新增
          path: '/EweWeaningAdd',
          name: 'EweWeaningAdd',
          component: () => import('../views/production_a/EweWeaningAdd.vue'),
        },
       
        {
          path: '/PurchaseView',
          name: 'PurchaseView',
          component: () => import('../views/PurchaseView.vue'),
        },

        {
          path: '/SaleView',
          name: 'SaleView',
          component: () => import('../views/SaleView.vue'),
        },
        {
          path: '/SheepDeathView',
          name: 'SheepDeathView',
          component: () => import('../views/SheepDeathView.vue'),
        },
        {
          path: '/PurchaseAddView',
          name: 'PurchaseAddView',
          component: () => import('../views/PurchaseAddView.vue'),
        },
        {
          path: '/SaleAddView',
          name: 'SaleAddView',
          component: () => import('../views/SaleAddView.vue'),
        },
        {
          path: '/SheepDeathAddView',
          name: 'SheepDeathAddView',
          component: () => import('../views/SheepDeathAddView.vue'),
        },

        {
          path: '/SheepfarmList',
          name: 'SheepfarmList',
          component: () => import('../views/Sheepfarm.vue/SheepfarmList.vue'),
        }


        ,
        {
          path: '/DongsheList',
          name: 'DongsheList',
          component: () => import('../views/Sheepfarm.vue/DongsheList.vue'),
        },

        {
          path: '/ColumnManagement',
          name: 'ColumnManagement',
          component: () => import('../views/Sheepfarm.vue/ColumnManagement.vue'),
        },

        {
          path: '/FarmHomeView',
          name: 'FarmHomeView',
          component: () => import('../views/FarmHomeView.vue'),
        },







        {
          path: '/HistoryRecords',
          name: 'HistoryRecords',
          component: () => import('../views/SheepFiles/HistoryRecordsList.vue'),
        },
        {
          path: '/HistoryRecordsAdd',
          name: 'HistoryRecordsAdd',
          component: () => import('../views/SheepFiles/HistoryRecordsAdd.vue'),
        },
        {
          path: '/PhaseBegin1',
          name: 'PhaseBegin1',
          component: () => import('../views/SheepFiles/PhaseBegin1.vue'),
        },
        {
          path: '/PhaseBeginAdd1',
          name: 'PhaseBeginAdd1',
          component: () => import('../views/SheepFiles/PhaseBeginAdd1.vue'),
        },
        {
          path: '/PhaseBegin2',
          name: 'PhaseBegin2',
          component: () => import('../views/SheepFiles/PhaseBegin2.vue'),
        },
        {
          path: '/PhaseBeginAdd2',
          name: 'PhaseBeginAdd2',
          component: () => import('../views/SheepFiles/PhaseBeginAdd1.vue'),
        },
        {
          path: '/SheepFilesList',
          name: 'SheepFilesList',
          component: () => import('../views/SheepFiles/SheepFilesList.vue'),
        },
        {
          path: '/SheepFilesDetail',
          name: 'SheepFilesDetail',
          component: () => import('../views/SheepFiles/SheepFilesDetail.vue'),
        },

        {
          path: '/EliminationList',
          name: 'EliminationList',
          component: () => import('../views/Sheepfarm.vue/EliminationList.vue'),
        },
        {
          path: '/EliminationAdd',
          name: 'EliminationAdd',
          component: () => import('../views/Sheepfarm.vue/EliminationAdd.vue'),
        },
        {
          path: '/TestElimination',
          name: 'TestElimination',
          component: () => import('../views/TestElimination.vue'),
        },
        {
          path: '/TestEweLambing',
          name: 'TestEweLambing',
          component: () => import('../views/TestEweLambing.vue'),
        },

        {
          path: '/SheepFilesAdd1',
          name: 'SheepFilesAdd1',
          component: () => import('../views/SheepFiles/SheepFilesAdd1.vue'),
        },

                {
          path: '/SheepFilesAdd2',
          name: 'SheepFilesAdd2',
          component: () => import('../views/SheepFiles/SheepFilesAdd2.vue'),
        },

         {
          path: '/SheepFilesAdd3',
          name: 'SheepFilesAdd3',
          component: () => import('../views/SheepFiles/SheepfilesAdd3.vue'),
        },

        


















      ]
    },
  ],
})

// 路由守卫
router.beforeEach((to, from, next) => {
  const token = localStorage.getItem('token')
  const userInfo = localStorage.getItem('userInfo')

  // 如果访问登录页面
  if (to.path === '/') {
    if (token && userInfo) {
      // 已登录，跳转到首页
      next('/home')
    } else {
      // 未登录，放行
      next()
    }
    return
  }

  // 其它页面，未登录则跳转到登录页
  if (!token || !userInfo) {
    next('/')
  } else {
    next()
  }
})

export default router
